<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class caidathethong_db 
	{
		public function CapNhat($ThoiGianDangXuat, $EThayDoiCapQuyen, $EKhiDatLaiMatKhau, $EKhiXoaNguoiDung, $EKhiCapNhatNguoiDung, $EKhiThemNguoiDung)
		{
			$sql = "UPDATE `tbl_caidathethong` SET ";
			$tmp = 0;
			
			if($ThoiGianDangXuat != -1)
			{
				$tmp = 1;
				$sql .= " `ThoiGianDangXuat` = '$ThoiGianDangXuat' ";
			}
			
			if($EThayDoiCapQuyen != -1)
			{
				$t = ($tmp == 1) ? " , " : "" ;
				$tmp = 1;
				$sql .= $t . " `EThayDoiCapQuyen` = '$EThayDoiCapQuyen' ";
			}
			if($EKhiDatLaiMatKhau != -1)
			{
				$t = ($tmp == 1) ? " , " : "" ;
				$tmp = 1;
				$sql .= $t . " `EKhiDatLaiMatKhau` = '$EKhiDatLaiMatKhau' ";
			}
			
			if($EKhiXoaNguoiDung != -1)
			{
				$t = ($tmp == 1) ? " , " : "" ;
				$tmp = 1;
				$sql .= $t . " `EKhiXoaNguoiDung` = '$EKhiXoaNguoiDung' ";
			}
			
			if($EKhiCapNhatNguoiDung != -1)
			{
				$t = ($tmp == 1) ? " , " : "" ;
				$tmp = 1;
				$sql .= $t . " `EKhiCapNhatNguoiDung` = '$EKhiCapNhatNguoiDung' ";
			}
			if($EKhiThemNguoiDung != -1)
			{
				$t = ($tmp == 1) ? " , " : "" ;
				$tmp = 1;
				$sql .= $t . " `EKhiThemNguoiDung` = '$EKhiThemNguoiDung' ";
			}
			$sql .= " WHERE 1 ";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($ThoiGianDangXuat, $EThayDoiCapQuyen, $EKhiDatLaiMatKhau, $EKhiXoaNguoiDung, $EKhiCapNhatNguoiDung, $EKhiThemNguoiDung)
		{
			$sql = "SELECT * FROM `tbl_caidathethong` WHERE 1  ";
			if($ThoiGianDangXuat != -1)
				$sql .= " AND `ThoiGianDangXuat` = '$ThoiGianDangXuat' ";

			if($EThayDoiCapQuyen != -1)
				$sql .= " AND `EThayDoiCapQuyen` = '$EThayDoiCapQuyen' ";

			if($EKhiDatLaiMatKhau != -1)
				$sql .= " AND `EKhiDatLaiMatKhau` = '$EKhiDatLaiMatKhau' ";

			if($EKhiXoaNguoiDung != -1)
				$sql .= " AND `EKhiXoaNguoiDung` = '$EKhiXoaNguoiDung' ";

			if($EKhiCapNhatNguoiDung != -1)
				$sql .= " AND `EKhiCapNhatNguoiDung` = '$EKhiCapNhatNguoiDung' ";

			if($EKhiThemNguoiDung != -1)
				$sql .= " AND `EKhiThemNguoiDung` = '$EKhiThemNguoiDung' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

